package com.longcai.piaojia.conn;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/10/17.
 */
@HttpInlet(Conn.ORDER_BALANCEDETAIL)
public class OrderBalanceDetailGet extends BaseAsyGet<OrderBalanceDetailGet.BalanceDetailListEntity> {

    public String user_id;
    public int page;

    public OrderBalanceDetailGet(AsyCallBack<BalanceDetailListEntity> asyCallBack) {
        super(asyCallBack);
    }

    @Override
    protected BalanceDetailListEntity parser(JSONObject object) throws Exception {

        TOAST = object.optString("message");

        if (object.optInt("code") == 200) {

            BalanceDetailListEntity balanceDetailListEntity = new BalanceDetailListEntity();

            JSONObject objectEntity = object.optJSONObject("data");

            balanceDetailListEntity.total = objectEntity.optInt("total");
            balanceDetailListEntity.per_page = objectEntity.optInt("per_page");
            balanceDetailListEntity.current_page = objectEntity.optInt("current_page");

            JSONArray array = objectEntity.optJSONArray("data");

            for (int i = 0; i < array.length(); i++) {

                JSONObject objectDetail = array.optJSONObject(i);

                BalanceDetailEntity balanceDetailEntity = new BalanceDetailEntity();

                balanceDetailEntity._id = objectDetail.optString("_id");
                balanceDetailEntity.type = objectDetail.optString("type");
                balanceDetailEntity.balance_type = objectDetail.optString("balance_type");
                balanceDetailEntity.money = objectDetail.optString("money");
                balanceDetailEntity.posttime = objectDetail.optString("posttime");


                balanceDetailListEntity.BalanceDetailList.add(balanceDetailEntity);
            }


            return balanceDetailListEntity;

        }




        return null;
    }

    public static class BalanceDetailListEntity {

//        "total": 11, //总条数
//                "per_page": 10,//每页几条
//                "current_page": 1,//第几页
        public int total, per_page, current_page;

        public List<BalanceDetailEntity> BalanceDetailList = new ArrayList<>();
    }

    public static class BalanceDetailEntity {

//        "_id": {},
//                "type": "2", //状态    1获得  2支出
//                "balance_type": "1",//余额类型  1普通余额 2惠民余额
//                "money": "1624.21", //金额
//                "posttime": "2016-10-17" //时间

        public String _id, type, balance_type, money, posttime;


    }


}
